import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:get/get.dart';

class CommonDialog extends StatelessWidget {
  final Widget? child;
  final Color? bgColor;
  final EdgeInsetsGeometry? margin;
  final EdgeInsetsGeometry? padding;
  final bool canTapClose;

  const CommonDialog({
    super.key,
    required this.child,
    this.bgColor = const Color(0xff030F18),
    this.margin = const EdgeInsets.symmetric(horizontal: 32),
    this.padding = const EdgeInsets.fromLTRB(24, 32, 24, 24),
    this.canTapClose = true,
  });

  @override
  Widget build(BuildContext context) {
    return Material(
      color: Colors.transparent, //不要设置此颜色，渲染会有延迟
      child: InkWell(
        onTap: () => Get.back(),
        child: BackdropFilter(
          filter: ImageFilter.blur(
            sigmaX: 4,
            sigmaY: 4,
          ),
          child: Center(
            child: GestureDetector(
              behavior: HitTestBehavior.opaque,
              onTap: canTapClose == true ? null : () {},
              child: Container(
                margin: margin,
                padding: padding,
                decoration: BoxDecoration(
                  color: bgColor,
                  borderRadius: BorderRadius.circular(12),
                ),
                child: child,
              ),
            ),
          ),
        ),
      ),
    );
  }
}

class CommonBottomSheet extends StatelessWidget {
  final Widget? child;
  final Color? bgColor;
  final EdgeInsetsGeometry? margin;
  final EdgeInsetsGeometry? padding;

  const CommonBottomSheet({
    super.key,
    required this.child,
    this.bgColor = const Color(0xff030F18),
    this.margin = const EdgeInsets.symmetric(horizontal: 32),
    this.padding = const EdgeInsets.fromLTRB(24, 32, 24, 24),
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: margin,
      padding: padding,
      decoration: BoxDecoration(
        color: bgColor,
        borderRadius: BorderRadius.circular(12),
      ),
      child: child,
    );
  }
}
